<extend name="public/form"/>
<block name="css"></block>
<block name="content">
    <div class="layui-card-header ">
        <span class="layui-breadcrumb">
          <a href="/admin" target="_blank">首页</a>
          <a href="javascript:;">采集管理</a>
          <a href="javascript:;" onclick="parent.xadmin.add_tab('采集任务管理','{:url('index')}')">采集任务管理</a>
          <a><cite>添加采集详情</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="layui-card-body"><!--选项卡父容器必须包含layui-tab class-->
        <form id="form1" class="layui-form">
            <input type="hidden" name="type" value="{$data->type}">
            <div class="layui-form-item">
                <label class="layui-form-label">采集任务名</label>
                <div class="layui-input-block">
                    <input type="text" value="{$data->name}" name="name"  lay-reqtext="请输入采集任务名"
                           placeholder="请输入采集任务名"
                           autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">绑定采集规则</label>
                <div class="layui-input-block">
                    <select name="collect_rule_id" lay-verify="required" lay-reqtext="请绑定采集规则" lay-search=""search>
                        <option value=""></option>
                        <foreach $collectRules as $vo>
                            <option <if condition="$data.collect_rule_id==$vo.id">selected</if> value="{$vo.id}">{$vo.name}</option>
                        </foreach>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">任务列表</label>
                <div class="layui-input-block">
                    <select name="matching_start" lay-verify="required" lay-reqtext="请选择已经采集完成的任务列表" lay-search=""search>
                        <option value=""></option>
                        <foreach $collectTasks as $vo>
                            <option <if condition="$data.matching_start==$vo.id">selected</if> value="{$vo.id}">{$vo.name}</option>
                        </foreach>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">属性key</label>
                <div class="layui-input-block">
                    <input type="text" value="{$data->matching}" name="matching" lay-verify="required" placeholder="请输入已成功采集的属性key"
                           autocomplete="off" class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="submit_table1">立即提交
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</block>
<block name="js">
    <script>
        layui.use(['jquery', 'form', 'layer', 'element'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;
            layui.element.render();
            form.on('submit(submit_table1)', function (data) {
                    let send_json = data.field;
                    $.ajax({
                        url: '/admin/collect_task/edit_type3?id={$data->id}',
                        method: 'post',
                        data: send_json,
                        success: function (res) {
                            if (res.code == 0) {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                //关闭当前frame
                                parent.layer.close(index);
                            } else {
                                layer.msg(res.msg, {icon: 5});
                            }
                        },
                        error: function (data) {
                            layer.msg('服务器繁忙', {icon: 5});
                        }
                    });
                    return false;
                }
            )
        });

    </script>
</block>